package cj.web.admin.controllers;

import java.util.EnumSet;
import java.util.List;

import net.paoding.rose.web.annotation.Path;
import net.paoding.rose.web.annotation.rest.Get;
import net.paoding.rose.web.annotation.rest.Post;
import net.paoding.rose.web.var.Model;
import net.sf.json.JSONObject;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;

import cj.web.admin.dao.GameDAO;
import cj.web.admin.dao.PermitDAO;
import cj.web.admin.domain.Game;
import cj.web.admin.domain.Permit;
import cj.web.constants.GameTypeEnum;
import cj.web.constants.MemuEnum;
import cj.web.constants.PermitStatusEnum;

@Path("/permit")
public class PermitController{

	private static Logger logger = Logger.getLogger(PermitController.class.getName());
	
	@Autowired
	private GameDAO gameDao;
	@Autowired
	private PermitDAO permitDao;
	
	@Get("show")
	public String show(Model model,Permit permit) {
	
		//MemuEnum
        model.add("MemuEnum",MemuEnum.cszh);
        List<Game> objs = gameDao.queryAll();
        model.add("gameObjs",objs);
        model.add("permitStatus",EnumSet.allOf(PermitStatusEnum.class));
		return "/views/game/permitList.vm";
	}

	@Post("getList")
	public String queryList(Permit permit) {
	
		JSONObject jo = new JSONObject();
		
		List<Permit> objs = permitDao.query(permit);
		
		for(Permit obj:objs){
			obj.setStatusName(PermitStatusEnum.getName(obj.getStatus()));
		}
		
		int size = permitDao.querysize(permit);
		jo.put("data", objs);
		jo.put("draw", permit.getDraw());
		jo.put("recordsTotal", size);
		jo.put("recordsFiltered", size);
		return "@"+jo.toString();
	}
}